//
//  ST_BaseNavigationController.m
//  ST_BaseMall
//
//  Created by 昱胜 on 2022/9/2.
//

#import "ST_BaseNavigationController.h"

@interface ST_BaseNavigationController ()<UINavigationControllerDelegate>

@property (nonatomic, getter=isPushing) BOOL pushing;

@end

@implementation ST_BaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = YES;
    }
    NSArray *array = [NSArray arrayWithObjects:[self class], nil]; //iOS9.0后使用
    UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:array];
    navBar.backgroundColor = [UIColor appBGColor];//导航栏背景颜色
    NSMutableDictionary *attribute = [NSMutableDictionary dictionary];
    attribute[NSForegroundColorAttributeName] = [UIColor appNavTitleColor];
    attribute[NSFontAttributeName] = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
    navBar.titleTextAttributes = attribute;
    UIImage *backgroundImage = [UIImage imageWithColor:[UIColor appBGColor]];
    [navBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
    [navBar setShadowImage:[UIImage new]];
    
    //设置状态栏颜色
    navBar.barTintColor = [UIColor orangeColor];
    navBar.barStyle = UIBarStyleBlack;
}
#pragma mark UINavigationControllerDelegate
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    viewController.hidesBottomBarWhenPushed = self.viewControllers.count > 0;
    if (self.pushing == YES) {
        NSLog(@"被拦截");
        return;
    } else {
//        NSLog(@"push");
        self.pushing = YES;
    }
    [super pushViewController:viewController animated:animated];
}
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    self.pushing = NO;
}
/**
 设置导航栏样式
 */
+ (void)load {
    

}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleDarkContent;
}
- (BOOL)shouldAutorotate{
    return self.visibleViewController.shouldAutorotate;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return self.visibleViewController.supportedInterfaceOrientations;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return self.visibleViewController.preferredInterfaceOrientationForPresentation;
}
- (BOOL)prefersStatusBarHidden {
    return [self.visibleViewController prefersStatusBarHidden];
}

@end
